﻿Imports Microsoft.Reporting.WinForms
Imports System.Data.SqlClient
Public Class FormReportStudent

    Private Sub FormReportStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql = "SELECT * FROM TBL_STUDENT WHERE NAME LIKE N'%" & Me.TextBox1.Text & "%' "
        If Me.ComboBox1.Text <> "(All)" Then
            sql = sql + " AND SEX=N'" & Me.ComboBox1.Text & "'"
        End If
        Dim cn As New SqlConnection("server=.;uid=sa;pwd=123;database=SchoolDb;")
        cn.Open()
        Dim cmd As New SqlCommand(Sql, cn)
        Dim dr = cmd.ExecuteReader()
        Dim dt As New DataTable
        dt.Load(dr)
        dr.Close()

        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("SchoolDataSet_TBL_STUDENT", dt))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "SchoolApp.ReportStudent.rdlc"

        Dim ps As New List(Of ReportParameter)
        ps.Add(New ReportParameter("Name", Me.TextBox1.Text))
        ps.Add(New ReportParameter("Sex", Me.ComboBox1.Text))
        Me.ReportViewer1.LocalReport.SetParameters(ps)

        Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
        Me.ReportViewer1.ZoomMode = ZoomMode.FullPage
        Me.ReportViewer1.RefreshReport()
    End Sub
End Class